package com.miyu.client1.utils.Result;

import org.apache.poi.ss.formula.functions.T;

import java.lang.reflect.ParameterizedType;

public class ResultUtil {
    /**
     * 成功时生成result的方法,有返回数据
     */
    public static <T> Result<T> success(T t){
        System.out.println(t.getClass());

        Result<T> result = new Result<>();
        result.setState(ResultEnum.SUCCESS.getCode());
        result.setMsg(ResultEnum.SUCCESS.getMsg());
        result.setCode("0");
        result.setData(t);
        return result;
    }

    /**
     * 成功时生成result的方法,无返回数据
     */
    public static <T> Result<T> success(){
        return success(null);
    }

    /**
     * 失败时生成result的方法
     */
    public static <T> Result<T> error(int status, String msg){
        Result<T> result = new Result<>();
        result.setState(status);
        result.setMsg(msg);
        return result;
    }
}
enum  ResultEnum{
    UNKNOWN_ERROR(-1, "未知错误"),
    SUCCESS(0, "接收数据成功"),
    BASIC_INFO_ID_IS_EMPTY(600, "基本信息中BasicInfoId为空"),
    BASIC_INFO_ADD_TO_DATABASE_FAILURE(601, "向数据库添加基本信息失败"),
    DETAILS_DATA_BASIC_INFO_ID_IS_EMPTY(602, "测试数据中BasicInfoId为空"),
    DETAILS_DATA_ADD_TO_DATABASE_FAILURE(603, "向数据库添加测试数据失败");

    ResultEnum(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    private int code;

    private String msg;

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    @Override
    public String toString() {
        return "ResultEnum{" +
                "code=" + code +
                ", msg='" + msg + '\'' +
                '}';
    }
}
